package com.ruoyi.reunion.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.reunion.domain.ActivityComment;
import com.ruoyi.reunion.service.IActivityCommentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动评论Controller
 * 
 * @author ccccc
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/reunion/comment")
public class ActivityCommentController extends BaseController
{
    @Autowired
    private IActivityCommentService activityCommentService;


    @PostMapping("/addComment")
    public AjaxResult addComment(@RequestBody ActivityComment activityComment)
    {
        activityComment.setUserId(getUserId());
        activityComment.setUsername(getUsername());
        activityComment.setAvatar(getLoginUser().getUser().getAvatar());
        activityComment.setStatus(1L);

        return toAjax(activityCommentService.insertActivityComment(activityComment));
    }
    @PostMapping("/addActivityComment")
    private AjaxResult addActivityComment(@RequestBody ActivityComment activityComment) {
//        ActivityComment activityComment1 = new ActivityComment();
//        activityComment1.setActivityId(activityComment.getActivityId());
//        activityComment1.setUserId(getUserId());
//        activityComment1.setContent(activityComment.getContent());
////        activityComment1.setCreateTime(new Date());
//        activityComment1.setUsername(getUsername());
//        activityComment1.setAvatar(getLoginUser().getUser().getAvatar());
//        activityComment1.setStatus(1L);



        System.out.println(activityComment);
        activityCommentService.insertActivityComment(activityComment);

        return AjaxResult.success();
    }
    /**
     * 查询活动评论列表
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityComment activityComment)
    {
        startPage();
        List<ActivityComment> list = activityCommentService.selectActivityCommentList(activityComment);
        return getDataTable(list);
    }

    /**
     * 导出活动评论列表
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:export')")
    @Log(title = "活动评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityComment activityComment)
    {
        List<ActivityComment> list = activityCommentService.selectActivityCommentList(activityComment);
        ExcelUtil<ActivityComment> util = new ExcelUtil<ActivityComment>(ActivityComment.class);
        util.exportExcel(response, list, "活动评论数据");
    }

    /**
     * 获取活动评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityCommentService.selectActivityCommentById(id));
    }

    /**
     * 新增活动评论
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:add')")
    @Log(title = "活动评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityComment activityComment)
    {
        return toAjax(activityCommentService.insertActivityComment(activityComment));
    }

    /**
     * 修改活动评论
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:edit')")
    @Log(title = "活动评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityComment activityComment)
    {
        return toAjax(activityCommentService.updateActivityComment(activityComment));
    }

    /**
     * 删除活动评论
     */
    @PreAuthorize("@ss.hasPermi('reunion:comment:remove')")
    @Log(title = "活动评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityCommentService.deleteActivityCommentByIds(ids));
    }
}
